package pers.w.chaptertalk.funs.db;

import android.content.Context;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

import pers.w.chaptertalk.funs.Fun;

public  class MyDB_Helper extends SQLiteOpenHelper {

    static final String DB_NAME = "chapter_talk";
   /* public static final String _ID = "_id";

    static final String CHAPTER_ID = "chapter_id";

    String[] fields;*/

   /* public static final String NAME = "name";
    public static final String URI = "uri";
    public static final String AUTHOR = "author";
    public static final String INTRODUCTION = "introduction";
    public static final String IMG = "img";
    public static final String TYPE = "type";
    public static final String LASTCHAPTERNAME = "lastChapterName";
    public static final String LASTUPDATETIME = "lastUpdateTime";*/

    Resources resources;
    //SQLiteDatabase db;

    MyDB_Helper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        assert context != null;
        this.resources = context.getResources();
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        if (Fun.isDebug()) Log.d("DB_", Tab_Book.CREATE_SQL(resources));
        db.execSQL(Tab_Book.CREATE_SQL(resources));

        if (Fun.isDebug()) Log.d("DB_", Tab_Chapter.CREATE_SQL);
        db.execSQL(Tab_Chapter.CREATE_SQL);

        if (Fun.isDebug()) Log.d("DB_", Tab_BookProgress.CREATE_SQL);
        db.execSQL(Tab_BookProgress.CREATE_SQL);
    }

    MyDB_Helper(@Nullable Context context){
        this(context, MyDB_Helper.DB_NAME, null, 1);
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }


}
